package com.zxc.model;

import com.zxc.enums.Fruit;
import java.util.HashMap;
import java.util.Map;

/**
 * 购物车类
 */
public class ShoppingCart {
    private final Map<Fruit, Integer> fruits;

    public ShoppingCart() {
        this.fruits = new HashMap<>();
    }

    public void addFruit(Fruit fruit, int weight) {
        if (weight < 0) {
            throw new IllegalArgumentException("水果重量不能为负数");
        }
        fruits.put(fruit, fruits.getOrDefault(fruit, 0) + weight);
    }

    public Map<Fruit, Integer> getFruits() {
        return new HashMap<>(fruits);
    }

    public void clear() {
        fruits.clear();
    }
}
